module.exports = function(window, document) {
	var apivm = require('../../common/avm.min')(window, document);
	var avm = apivm;
	var api = apivm.api;
	var Component = apivm.Component;
	var $ = apivm.$;
	(function() {
	var Tabbar = /*@__PURE__*/ (function(Component) {
		function Tabbar(props) {
			Component.call(this, props);
			this.data = {};
		}

		if (Component) Tabbar.__proto__ = Component;
		Tabbar.prototype = Object.create(Component && Component.prototype);
		Tabbar.prototype.constructor = Tabbar;
		Tabbar.prototype.apiready = function() {};
		Tabbar.prototype.goPage = function(pagename) {
			var pagePath = {
				index: "../index/index",
				friend: "../friend/friend",
				message: "../message/message",
				me: "../me/me",
				addVideo: "../addVideo/addVideo"
			};

			wx.redirectTo({url: pagePath[pagename]});
		};
		Tabbar.prototype.render = function() {
			var this$1 = this;
			return apivm.h(
				"view",
				{class: "tabbar"},
				apivm.h(
					"view",
					{
						class: "tab-item",
						style: {color: this.props.active == "index" ? "#fff" : "#bbb"},
						onClick: function() {
							return this$1.goPage("index");
						}
					},
					"首页"
				),
				apivm.h(
					"view",
					{
						class: "tab-item",
						style: {color: this.props.active == "friend" ? "#fff" : "#bbb"},
						onClick: function() {
							return this$1.goPage("friend");
						}
					},
					"朋友"
				),
				apivm.h(
					"view",
					{
						class: "tab-item",
						onClick: function() {
							return this$1.goPage("addVideo");
						}
					},
					apivm.h("image", {src: "../../image/add.png"})
				),
				apivm.h(
					"view",
					{
						class: "tab-item",
						style: {color: this.props.active == "message" ? "#fff" : "#bbb"},
						onClick: function() {
							return this$1.goPage("message");
						}
					},
					"消息"
				),
				apivm.h(
					"view",
					{
						class: "tab-item",
						style: {color: this.props.active == "me" ? "#fff" : "#bbb"},
						onClick: function() {
							return this$1.goPage("me");
						}
					},
					"我"
				)
			);
		};

		return Tabbar;
	})(Component);
	apivm.define("tabbar", Tabbar);

	var Tpl = /*@__PURE__*/ (function(Component) {
		function Tpl(props) {
			Component.call(this, props);
			this.data = {
				isShow: "none",
				videoContext: null,
				current: 0,
				page: 1,
				videoList: [
					{
						id: "000",
						nickname: "老陈打码",
						content: "新年快乐，万事如意！",
						like: "3.5w",
						share: "3821",
						collect: "2988",
						comment: "3475",
						isLike: false,
						pubtime: "2022-01-10 01:30",
						headimg: "https://a415432669.github.io/shortvideo/000.jpg",
						src: "https://a415432669.github.io/shortvideo/000.mp4"
					},

					{
						id: "001",
						nickname: "学习通知",
						content: "快乐学习APICloud多端应用开发",
						like: "3.5w",
						share: "3821",
						collect: "2988",
						comment: "3475",
						isLike: false,
						pubtime: "2022-01-10 01:30",
						headimg: "https://a415432669.github.io/shortvideo/001.jpg",
						src: "https://a415432669.github.io/shortvideo/001.mp4"
					}
				]
			};
		}

		if (Component) Tpl.__proto__ = Component;
		Tpl.prototype = Object.create(Component && Component.prototype);
		Tpl.prototype.constructor = Tpl;
		Tpl.prototype.apiready = function() {
			var this$1 = this;

			document
				.querySelector("#video" + this.data.current)
				.$$getContext()
				.then(function(context) {
					this$1.data.videoContext = context;
					this$1.data.videoContext.play();
				});
		};
		Tpl.prototype.handleClick = function(e) {
			api.toast({msg: this.data.text, location: "middle"});
		};
		Tpl.prototype.onchange = function(event) {
			var this$1 = this;
			// console.log(event.detail.current)
			this.data.current = event.detail.current;
			if (this.data.current === this.data.videoList.length - 1) {
				this.data.page++;
				api.ajax(
					{
						url:
							"https://a6197037785854-dev.apicloud-saas.com/api/videos/getVideoList?obj=" +
							JSON.stringify({page: this.data.page, limit: 2})
					},
					function(ret, err) {
						// console.log(ret)
						// this.videoList = this.videoList.concat(ret.data)
						ret.data.forEach(function(item) {
							return this$1.data.videoList.push(item);
						});
						if (ret.data.length == 0) {
							api.toast({msg: "休息一下，视频很快会更新！"});
						}
					}
				);
			}
			this.data.videoContext && this.data.videoContext.pause();
			document
				.querySelector("#video" + this.data.current)
				.$$getContext()
				.then(function(context) {
					this$1.data.videoContext = context;
					this$1.data.videoContext.play();
				});
		};
		Tpl.prototype.togglePause = function() {
			this.data.videoContext.pause();
		};
		Tpl.prototype.togglePlay = function() {
			this.data.videoContext.play();
		};
		Tpl.prototype.onplay = function() {
			this.data.isShow = "none";
		};
		Tpl.prototype.onpause = function() {
			this.data.isShow = "flex";
		};
		Tpl.prototype.onended = function() {
			this.data.videoContext.play();
		};
		Tpl.prototype.likeFn = function() {
			this.data.videoList[this.data.current].isLike = !this.data.videoList[
				this.data.current
			].isLike;
		};
		Tpl.prototype.shareFn = function() {
			this.data.videoList[this.data.current].share++;
		};
		Tpl.prototype.render = function() {
			var this$1 = this;
			return apivm.h(
				"view",
				{class: "page"},
				apivm.h(
					"swiper",
					{
						class: "swiper",
						circular: false,
						vertical: true,
						onChange: this.onchange
					},
					(Array.isArray(this.data.videoList)
						? this.data.videoList
						: Object.values(this.data.videoList)
					).map(function(item$1, index$1) {
						return apivm.h(
							"swiper-item",
							{class: "swiper-item"},
							apivm.h("video", {
								src: item$1.src,
								controls: false,
								id: "video" + index$1,
								onclick: function(event) {
									if (this$1.togglePause) {
										this$1.togglePause(event);
									} else {
										togglePause(event);
									}
								},
								onpause: function(event) {
									if (this$1.onpause) {
										this$1.onpause(event);
									} else {
										onpause(event);
									}
								},
								onplay: function(event) {
									if (this$1.onplay) {
										this$1.onplay(event);
									} else {
										onplay(event);
									}
								},
								onended: function(event) {
									if (this$1.onended) {
										this$1.onended(event);
									} else {
										onended(event);
									}
								}
							})
						);
					})
				),

				apivm.h(
					"view",
					{class: "rightBar"},
					apivm.h(
						"div",
						{class: "right-item", onClick: this.likeFn},
						this.data.videoList[this.data.current].isLike
							? apivm.h("image", {src: "../../image/heart_active.png"})
							: apivm.h("image", {src: "../../image/heart.png"}),

						apivm.h("text", null, this.data.videoList[this.data.current].like)
					),
					apivm.h(
						"div",
						{class: "right-item"},
						apivm.h("image", {src: "../../image/comment.png"}),
						apivm.h("text", null, this.data.videoList[this.data.current].comment)
					),
					apivm.h(
						"div",
						{class: "right-item"},
						apivm.h("image", {src: "../../image/collect.png"}),
						apivm.h("text", null, this.data.videoList[this.data.current].collect)
					),
					apivm.h(
						"div",
						{class: "right-item", onClick: this.shareFn},
						apivm.h("image", {src: "../../image/share.png"}),
						apivm.h("text", null, this.data.videoList[this.data.current].share)
					)
				),

				apivm.h(
					"view",
					{class: "desc"},
					apivm.h(
						"view",
						{class: "nickname"},
						"@ ",
						this.data.videoList[this.data.current].nickname
					),
					apivm.h(
						"view",
						{class: "content"},
						this.data.videoList[this.data.current].content
					)
				),

				apivm.h(
					"div",
					{
						class: "playBtn",
						style: {display: this.data.isShow},
						onClick: this.togglePlay
					},
					apivm.h("image", {src: "../../image/pause.png"})
				),
				apivm.h("tabbar", {active: "index"})
			);
		};

		return Tpl;
	})(Component);
	apivm.define("tpl", Tpl);
	apivm.render(apivm.h("tpl", null), "body");
})();

	window['createApp'] = function() {
		apivm.$_start();
	}
	return avm;
}